package com.java110.mall.cart.api;

import com.alibaba.fastjson.JSONObject;
import com.java110.mall.cart.bmo.housekeepingServFee.IDeleteHousekeepingServFeeBMO;
import com.java110.mall.cart.bmo.housekeepingServFee.IGetHousekeepingServFeeBMO;
import com.java110.mall.cart.bmo.housekeepingServFee.ISaveHousekeepingServFeeBMO;
import com.java110.mall.cart.bmo.housekeepingServFee.IUpdateHousekeepingServFeeBMO;
import com.java110.dto.housekeeping.HousekeepingServFeeDto;
import com.java110.po.housekeeping.HousekeepingServFeePo;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/housekeepingServFee")
public class HousekeepingServFeeApi {

    @Autowired
    private ISaveHousekeepingServFeeBMO saveHousekeepingServFeeBMOImpl;
    @Autowired
    private IUpdateHousekeepingServFeeBMO updateHousekeepingServFeeBMOImpl;
    @Autowired
    private IDeleteHousekeepingServFeeBMO deleteHousekeepingServFeeBMOImpl;

    @Autowired
    private IGetHousekeepingServFeeBMO getHousekeepingServFeeBMOImpl;

    /**
     * 微信保存消息模板
     * @serviceCode /housekeepingServFee/saveHousekeepingServFee
     * @path /app/housekeepingServFee/saveHousekeepingServFee
     * @param reqJson
     * @return
     */
    @RequestMapping(value = "/saveHousekeepingServFee", method = RequestMethod.POST)
    public ResponseEntity<String> saveHousekeepingServFee(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "configId", "请求报文中未包含configId");
        Assert.hasKeyAndValue(reqJson, "feeName", "请求报文中未包含feeName");
        /*Assert.hasKeyAndValue(reqJson, "hktId", "请求报文中未包含hktId");*/
        Assert.hasKeyAndValue(reqJson, "shopId", "请求报文中未包含shopId");



        HousekeepingServFeePo housekeepingServFeePo = BeanConvertUtil.covertBean(reqJson, HousekeepingServFeePo.class);
        return saveHousekeepingServFeeBMOImpl.save(housekeepingServFeePo,reqJson);
    }

    /**
     * 微信修改消息模板
     * @serviceCode /housekeepingServFee/updateHousekeepingServFee
     * @path /app/housekeepingServFee/updateHousekeepingServFee
     * @param reqJson
     * @return
     */
    @RequestMapping(value = "/updateHousekeepingServFee", method = RequestMethod.POST)
    public ResponseEntity<String> updateHousekeepingServFee(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "servId", "请求报文中未包含servId");
        Assert.hasKeyAndValue(reqJson, "servName", "请求报文中未包含servName");
        Assert.hasKeyAndValue(reqJson, "configId", "请求报文中未包含configId");
        Assert.hasKeyAndValue(reqJson, "feeName", "请求报文中未包含feeName");
        Assert.hasKeyAndValue(reqJson, "shopId", "请求报文中未包含shopId");
        Assert.hasKeyAndValue(reqJson, "servFeeId", "servFeeId不能为空");


        HousekeepingServFeePo housekeepingServFeePo = BeanConvertUtil.covertBean(reqJson, HousekeepingServFeePo.class);
        return updateHousekeepingServFeeBMOImpl.update(housekeepingServFeePo);
    }

    /**
     * 微信删除消息模板
     * @serviceCode /housekeepingServFee/deleteHousekeepingServFee
     * @path /app/housekeepingServFee/deleteHousekeepingServFee
     * @param reqJson
     * @return
     */
    @RequestMapping(value = "/deleteHousekeepingServFee", method = RequestMethod.POST)
    public ResponseEntity<String> deleteHousekeepingServFee(@RequestBody JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "shopId", "商铺ID不能为空");

        Assert.hasKeyAndValue(reqJson, "servFeeId", "servFeeId不能为空");


        HousekeepingServFeePo housekeepingServFeePo = BeanConvertUtil.covertBean(reqJson, HousekeepingServFeePo.class);
        return deleteHousekeepingServFeeBMOImpl.delete(housekeepingServFeePo);
    }

    /**
     * 微信删除消息模板
     * @serviceCode /housekeepingServFee/queryHousekeepingServFee
     * @path /app/housekeepingServFee/queryHousekeepingServFee
     * @param shopId 商铺ID
     * @return
     */
    @RequestMapping(value = "/queryHousekeepingServFee", method = RequestMethod.GET)
    public ResponseEntity<String> queryHousekeepingServFee(@RequestParam(value = "shopId") String shopId,
                                                      @RequestParam(value = "page") int page,
                                                      @RequestParam(value = "row") int row) {
        HousekeepingServFeeDto housekeepingServFeeDto = new HousekeepingServFeeDto();
        housekeepingServFeeDto.setPage(page);
        housekeepingServFeeDto.setRow(row);
        housekeepingServFeeDto.setShopId(shopId);
        return getHousekeepingServFeeBMOImpl.get(housekeepingServFeeDto);
    }
}
